package com.aceitunaproject.server.unit;

import java.util.Properties;
import java.util.logging.Logger;

import com.aceitunaproject.server.exceptions.gamerules.IllegalActionException;
import com.sun.sgs.impl.sharedutil.LoggerWrapper;
import com.sun.sgs.impl.util.AbstractService;
import com.sun.sgs.kernel.ComponentRegistry;
import com.sun.sgs.service.TransactionProxy;

/**
 * Unit service implementation
 * 
 * @author Maciej Miechowicz
 */
public class UnitServiceImpl extends AbstractService implements UnitService {

    private static final LoggerWrapper logger = 
    	new LoggerWrapper(Logger.getLogger("com.aceitunaproject.unit"));

    /**
	 * Creates a new instance of the service
	 * 
	 * @param properties application properties
	 * @param systemRegistry component registry
	 * @param txnProxy transaction proxy
	 */
	public UnitServiceImpl(
			Properties properties,
			ComponentRegistry systemRegistry,
			TransactionProxy txnProxy)
	{
		super(properties, systemRegistry, txnProxy, logger);
	}
	
	/**
	 * Handles service startup
	 */
	@Override
	protected void doReady() {
	}

	/**
	 * Handles service shutdown
	 */
	@Override
	protected void doShutdown() {
	}

	/**
	 * Handles service version mismatch
	 * 
	 * @param oldVersion old version
	 * @param currentVersion current version
	 */
	@Override
	protected void handleServiceVersionMismatch(Version oldVersion, Version currentVersion) {
		throw new UnsupportedOperationException("Unsupported operation");
	}

	/**
	 * {@inheritDoc}
	 */
	public void moveUnit(long unitId, long destinationX, long destinationY)
			throws IllegalActionException {
		logger.getLogger().fine("moving unit id " + unitId + " to " + destinationX + " , "
				+ destinationY);
		
		
		// TODO actually move the unit
		
		
	}

}
